package main

import (
	"fmt"
	_ "fmt"
)

func main() {
	//演示 map切片
	//存放monster 每个monster都有name和age
	monsters := make([]map[string]string, 2)
	if monsters[0] == nil {
		monsters[0] = make(map[string]string, 2)
		monsters[0]["name"] = "怪物1"
		monsters[0]["age"] = "400"
	}

	if monsters[1] == nil {
		monsters[1] = make(map[string]string, 2)
		monsters[1]["name"] = "怪物2"
		monsters[1]["age"] = "100"
	}

	//切片越界，只能用append来追加
	// if monsters[2] == nil {
	// 	monsters[2] = make(map[string]string, 2)
	// 	monsters[2]["name"] = "怪物3"
	// 	monsters[2]["age"] = "100"
	// }

	newMonsters := map[string]string{
		"name": "怪物3",
		"age":  "500",
	}
	monsters = append(monsters, newMonsters)
	fmt.Println(monsters)
}
